<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="icon" href="./images/bitbug_favicon.ico">
    <link rel="stylesheet" href="./font_2481939_cgiqmkfadol/iconfont.css">
    <link rel="stylesheet" href="./css/login.css">
</head>

<body>
    <!-- 头部 -->
    <!-- <div id="bannaerbox">
        <h1 class="bannaerbox-h1">
            <img src="./imgs/logo.png" alt="">
            <span><a href="">新品推荐</a></span>
            <span><a href="">热卖榜单</a></span>
        </h1>

    </div> -->


    
    <div class="dl">
        <div class="dl-1 ">
            <div class="dl-2">
               
                <div class="dl-top">
                    <div class="dl-top-1">短信登录</div>
                    <div  class="dl-top-2">优享账号登录</div>
                    <input type="button" name="" id="close" value="&times;">        
                </div>
                <div class="dl-footer ">
                              <form action="http://10.11.52.91:3000/aaa" method="GET">
                        <input type="text" autocomplete="off" name="username" id="username" placeholder="手机号/用户名/邮箱" class="dl-footer-1">
                        <input type="password" autocomplete="off" name="password" id="possword" placeholder="密码" class="dl-footer-2">
                        <input type="submit" value="登录" name="" id="submit" class="dl-footer-3" >
                    </form>
                    <span class="dl-footer-4">
                        <a href="./regsiter.html" class="dl-footer-zc">快速注册</a>
                        <a href="" class="dl-footer-zc-1">找回密码</a>
                    </span>
                </div>
            </div>
        </div>
    </div>


</body>
<script src="./libs/jquery.2.2.4.js"></script>
<script>
    $("#submit").click(function () {
        // 收集用户输入的信息，通过ajax发往后端，等待返回信息
        $.ajax({
            url: "http://localhost:3000/api",
            data: {
                type: "login",
                username: $("#login_id").val(),
                password: $("#password").val()
            },
            success: res => {
                // 解析后端返回的信息，判断登录成功或是失败
                res = JSON.parse(res);
                console.log(res);
                // 成功
                if (res.code === 1) {
                    // 登录成功后，存储登录信息，以便登录守卫
                    localStorage.setItem("isLogin", "ok");
                    localStorage.setItem("username", res.data);
                    if (confirm("登录成功是否跳转到首页")) {
                        location.href = "./index.html"
                    }
                } else if (res.code === 0) {
                    if (confirm(res.title + "登录失败，是否跳转到注册")) {
                        location.href = "./register.html"
                    }
                } else if (res.code === 2) {
                    // 失败
                    alert(res.title + "，登录失败")
                }
            }
        })
    })
</script>

</html>